package 队列实现二叉树层序遍历;

import 链表实现队列.Queue;

public class Test {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(
                1,
                new TreeNode(2, new TreeNode(4, null, null), new TreeNode(5, null, null)),
                new TreeNode(3, new TreeNode(6, null, null), new TreeNode(7, null, null))
        );
        Queue<TreeNode> queue = new Queue<>();
        queue.offer(root);

        while (!queue.isEmpty()) {
            TreeNode n = queue.poll();
            System.out.println(n);
            if (n.left != null) {
                queue.offer(n.left);
            }
            if (n.right != null) {
                queue.offer(n.right);
            }
        }
    }
}
